package wangjg.android.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.LinearLayout;

public class MyLayout extends LinearLayout {

	public MyLayout(Context context) {
		super(context);
	}

	public MyLayout(Context context, AttributeSet attrs) {
		super(context, attrs);Log.d("", "MyLayout");
		this.setWillNotDraw(false);
	}
	
	protected void dispatchDraw(Canvas canvas){
		super.dispatchDraw(canvas);
		Log.d("MyLayout.dispatchDraw","do");
		drawCustomer(canvas);
	}
	
	protected void onDraw(Canvas canvas){
		Log.d("MyLayout.onDraw","begin");
		super.onDraw(canvas);
	}
	
	private void drawCustomer(Canvas canvas){
		Paint paint = new Paint();
		
		paint.setColor(Color.GREEN);
		paint.setTextSize(60);
		paint.setTextAlign(Align.CENTER);
		canvas.drawText("xxxxxxxx", 60, 60, paint);
		
		paint.setColor(Color.RED);
		paint.setStyle(Style.FILL);
		canvas.drawRect(new Rect(0, 0, 10, 10), paint);
		Log.d("MyLayout.onDraw","end");
	}
}
